var api = require('../../config/api.js');
var util = require('../../utils/util.js');
var user = require('../../utils/user.js');
var check = require('../../utils/check.js');
var wxCharts = require('../../utils/wxcharts.js');
var app = getApp();

// pages/home2/home2.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ind: {
      licenseInfo: "/static/images/toux1.jpg",
      name: "你还未登陆",
    },
    number: 0,
    dd: {
      todaySum: 0,
      todayIncome: 0
    }
  },
  send() {
    wx.navigateTo({
      url: '/pages/ shipped/ shipped',
    })
  },
  goperson() {
    wx.navigateTo({
      url: '/pages/person/person',
    })
  },
  goshopmanage() {
    wx.navigateTo({
      url: "/pages/manageshop/manageshop",
    })
  },
  goordermanage() {
    wx.navigateTo({
      url: "/pages/manageorder/manageorder",
    })
  },
  store() {
    wx.navigateTo({
      url: "/pages/store/store",
    })
  },
  getzt() {
    let that = this
    util.request(api.QueryAppInfo, {}, 'get', {
      'token': wx.getStorageSync('token')
    }).then(function(res) {
      console.log("sadsadad" + res)
      if (res.code == 200) {
        that.setData({
          ind: res.data.info
        })
        app.globalData.ind = res.data.info
        if (res.data.info.status != 0) {
          wx.redirectTo({
            url: '/pages/index/index',
          })
        }
      }
      if (res.code != 200) {
        wx.showModal({
          title: '错误提示',
          content: res.msg,
          showCancel: false
        })
      }
    })
  },
  onPullDownRefresh: function() {
    wx.showToast({
      title: '正在刷新数据...',
      icon: 'loading',
      duration: 2000
    });
    this.setData({
      fabus: []
    }); //先清空数据
    this.loadIndex(); //再重新加载数据
    wx: wx.stopPullDownRefresh(); //停止刷新操作
  },

  getorder() {

    let that = this
    util.request(api.QueryOrdersInfo, {

    }, 'GET', {
      "x-merchant-request-code": wx.getStorageSync("code"),
      'Content-Type': 'application/json;charset=UTF-8',
      'token': wx.getStorageSync('token')
    }).then(function(res) {
      if (res.code == 200) {
        console.log(res)
        that.setData({
          dd: res.data
        })
        app.globalData.info = res.data
       
      }
      if (res.code != 200) {
        wx.showModal({
          title: '错误提示',
          content: res.msg,
          showCancel: false
        })
      }

    });

  },


  getztf() {
    var bg = 0
    let that = this
    util.request(api.ShowOrderInfo + "/4", {}, 'get', {
      "x-merchant-request-code": wx.getStorageSync("code"),
      'token': wx.getStorageSync('token')
    }).then(function(res) {
      // console.log("sadsadad")
      var bb = res.data.info
      // var arr = Object.keys(bb);
      // console.log(arr.length);  //3
      console.log(bb)

      // for (var n = 0; n < arr.length;) {
      for (var i in bb) {

        // console.log(i)          //获得对象中键值对的“键”
        // console.log(bb[i])  //获得对象中键值对的“值”
        bg = bg + bb[i]

      }
      console.log(bg)
      that.setData({
        number: bg
      })
    })
  },

  // getzttt() {
  //   let that = this
  //   util.request(api.ShowOrderInfo + "/1", {
  //   }, 'get', {
  //       "x-merchant-request-code": wx.getStorageSync("code"),
  //       'token': wx.getStorageSync('token')
  //     }).then(function (res) {
  //       console.log("sadsadad" + res)
  //       if (res.code == 200) {
  //         console.log(res.data.info.todaySum)
  //         app.globalData.info = res.data.info
  //         console.log(app.globalData.info.todaySum)
  //       }
  //     })
  // },



  gohome(){
    wx.navigateTo({
      url: '/pages/home/home',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    if (wx.getStorageSync("token")) {
      this.getzt()
      this.getorder()
      this.getztf()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})